using System;
using System.ComponentModel;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Security.Permissions;
using System.Web;
using PickGold.Charting.Utilities;

namespace PickGold.Charting
{
	[SRDescription("DescriptionAttributeArrowAnnotation_ArrowAnnotation"), AspNetHostingPermission(SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal), AspNetHostingPermission(SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.Minimal)]
	public class ArrowAnnotation : Annotation
	{
		private int _arrowSize = 5;
		private ArrowStyle _arrowStyle;

		public ArrowAnnotation()
		{
			base.AnchorAlignment = ContentAlignment.TopLeft;
		}

		private GraphicsPath GetArrowPath(ChartGraphics graphics, RectangleF position)
		{
			var absoluteRectangle = graphics.GetAbsoluteRectangle(position);
			var location = absoluteRectangle.Location;
			var tf2 = new PointF(absoluteRectangle.Right, absoluteRectangle.Bottom);
			var num = tf2.X - location.X;
			var num2 = tf2.Y - location.Y;
			var num3 = (float)Math.Sqrt(num * num + num2 * num2);
			var path = new GraphicsPath();
			var num4 = 2.1f;
			PointF[] points = null;
			if (this.ArrowStyle == ArrowStyle.Simple)
			{
				points = new PointF[] { location, new PointF(location.X + (this.ArrowSize * num4), location.Y - (this.ArrowSize * num4)), new PointF(location.X + (this.ArrowSize * num4), location.Y - this.ArrowSize), new PointF(location.X + num3, location.Y - this.ArrowSize), new PointF(location.X + num3, location.Y + this.ArrowSize), new PointF(location.X + (this.ArrowSize * num4), location.Y + this.ArrowSize), new PointF(location.X + (this.ArrowSize * num4), location.Y + (this.ArrowSize * num4)) };
			}
			else if (this.ArrowStyle == ArrowStyle.DoubleArrow)
			{
				points = new PointF[] { location, new PointF(location.X + (this.ArrowSize * num4), location.Y - (this.ArrowSize * num4)), new PointF(location.X + (this.ArrowSize * num4), location.Y - this.ArrowSize), new PointF((location.X + num3) - (this.ArrowSize * num4), location.Y - this.ArrowSize), new PointF((location.X + num3) - (this.ArrowSize * num4), location.Y - (this.ArrowSize * num4)), new PointF(location.X + num3, location.Y), new PointF((location.X + num3) - (this.ArrowSize * num4), location.Y + (this.ArrowSize * num4)), new PointF((location.X + num3) - (this.ArrowSize * num4), location.Y + this.ArrowSize), new PointF(location.X + (this.ArrowSize * num4), location.Y + this.ArrowSize), new PointF(location.X + (this.ArrowSize * num4), location.Y + (this.ArrowSize * num4)) };
			}
			else
			{
				if (this.ArrowStyle != ArrowStyle.Tailed)
					throw new InvalidOperationException(SR.ExceptionAnnotationArrowStyleUnknown);

				var num5 = 2.1f;
				points = new PointF[] { location, new PointF(location.X + (this.ArrowSize * num4), location.Y - (this.ArrowSize * num4)), new PointF(location.X + (this.ArrowSize * num4), location.Y - this.ArrowSize), new PointF(location.X + num3, location.Y - (this.ArrowSize * num5)), new PointF((location.X + num3) - (this.ArrowSize * num5), location.Y), new PointF(location.X + num3, location.Y + (this.ArrowSize * num5)), new PointF(location.X + (this.ArrowSize * num4), location.Y + this.ArrowSize), new PointF(location.X + (this.ArrowSize * num4), location.Y + (this.ArrowSize * num4)) };
			}
			path.AddLines(points);
			path.CloseAllFigures();
			var angle = (float)Math.Atan(num2 / num * 180.0 / 3.1415926535897931);
			if (num < 0f)
				angle += 180f;
			using (var matrix = new Matrix())
			{
				matrix.RotateAt(angle, location);
				path.Transform(matrix);
			}
			return path;
		}

		internal override void Paint(Chart chart, ChartGraphics graphics)
		{
			PointF empty = PointF.Empty;
			PointF anchorLocation = PointF.Empty;
			SizeF size = SizeF.Empty;
			this.GetRelativePosition(out empty, out size, out anchorLocation);
			PointF tf3 = new PointF(empty.X + size.Width, empty.Y + size.Height);
			RectangleF position = new RectangleF(empty, new SizeF(tf3.X - empty.X, tf3.Y - empty.Y));
			if ((!float.IsNaN(empty.X) && !float.IsNaN(empty.Y)) && (!float.IsNaN(tf3.X) && !float.IsNaN(tf3.Y)))
			{
				using (GraphicsPath path = this.GetArrowPath(graphics, position))
				{
					if (base.Common.ProcessModePaint)
					{
						graphics.DrawPathAbs(path, this.BackColor.IsEmpty ? Color.White : this.BackColor, this.BackHatchStyle, string.Empty, ChartImageWrapMode.Scaled, Color.Empty, ChartImageAlignmentStyle.Center, this.BackGradientStyle, this.BackSecondaryColor, this.LineColor, this.LineWidth, this.LineDashStyle, PenAlignment.Center, this.ShadowOffset, this.ShadowColor);
					}
					if (base.Common.ProcessModeRegions)
					{
						base.Common.HotRegionsList.AddHotRegion(graphics, path, false, base.ReplaceKeywords(this.ToolTip), base.ReplaceKeywords(this.Url), base.ReplaceKeywords(this.MapAreaAttributes), base.ReplaceKeywords(base.PostBackValue), this, ChartElementType.Annotation);
					}
					this.PaintSelectionHandles(graphics, position, null);
				}
			}
		}

		[SRDescription("DescriptionAttributeAnchorAlignment"), Browsable(false), EditorBrowsable(EditorBrowsableState.Never), DefaultValue(typeof(ContentAlignment), "TopLeft"), SRCategory("CategoryAttributeAnchor")]
		public override ContentAlignment AnchorAlignment
		{
			get
			{
				return base.AnchorAlignment;
			}
			set
			{
				base.AnchorAlignment = value;
			}
		}

		[EditorBrowsable(EditorBrowsableState.Never), Browsable(false), SRDescription("DescriptionAttributeAnnotationType"), Bindable(true), SRCategory("CategoryAttributeMisc"), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden), SerializationVisibility(SerializationVisibility.Hidden)]
		public override string AnnotationType
		{
			get
			{
				return "Arrow";
			}
		}

		[ParenthesizePropertyName(true), Bindable(true), DefaultValue(5), SRDescription("DescriptionAttributeArrowAnnotation_ArrowSize"), SRCategory("CategoryAttributeAppearance")]
		public virtual int ArrowSize
		{
			get
			{
				return this._arrowSize;
			}
			set
			{
				if (value <= 0)
				{
					throw new ArgumentOutOfRangeException("value", SR.ExceptionAnnotationArrowSizeIsZero);
				}
				if (value > 100)
				{
					throw new ArgumentOutOfRangeException("value", SR.ExceptionAnnotationArrowSizeMustBeLessThen100);
				}
				this._arrowSize = value;
				this.Invalidate();
			}
		}

		[ParenthesizePropertyName(true)]
		[SRDescription("DescriptionAttributeArrowAnnotation_ArrowStyle")]
		[SRCategory("CategoryAttributeAppearance")]
		[Bindable(true)]
		[DefaultValue(0)]
		public virtual ArrowStyle ArrowStyle
		{
			get
			{
				return this._arrowStyle;
			}
			set
			{
				this._arrowStyle = value;
				this.Invalidate();
			}
		}

		[ParenthesizePropertyName(true)]
		[SRCategory("CategoryAttributeAppearance")]
		[DefaultValue(1)]
		[Browsable(false)]
		[EditorBrowsable(EditorBrowsableState.Never)]
		[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
		[SerializationVisibility(SerializationVisibility.Hidden)]
		[SRDescription("DescriptionAttributeSelectionPointsStyle")]
		internal override SelectionPointsStyle SelectionPointsStyle
		{
			get
			{
				return SelectionPointsStyle.TwoPoints;
			}
		}
	}
}

